package mil.af.amc.adpetracker.web.helpers;

import mil.af.amc.adpetracker.model.Model;
import mil.af.amc.adpetracker.model.comparators.ModelManufacturerComparator;
import mil.af.amc.adpetracker.model.comparators.ModelNameComparator;
import mil.af.amc.adpetracker.service.ModelService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;

/**
 * View Helper for Model objects
 *
 * @author TSgt Jason Ferguson
 */
@Service("modelViewHelper")
public class ModelViewHelper {

    private ModelService modelService;

    @Autowired
    public void setModelService(ModelService modelService) {
        this.modelService = modelService;
    }

    public List<Model> getAll() {

        List<Model> resultList = modelService.getAll();
        Collections.sort(resultList, new ModelNameComparator());
        Collections.sort(resultList, new ModelManufacturerComparator());
        return resultList;

    }
}
